package model

import (
	"gorm.io/gorm"
	"time"
	"user_service/global"
)

type User struct {
	Id         uint           `gorm:"column:id;type:bigint UNSIGNED;primaryKey;not null;" json:"id"`
	Mobile     string         `gorm:"column:mobile;type:varchar(20);not null;" json:"mobile"`
	Password   string         `gorm:"column:password;type:varchar(20);not null;" json:"password"`
	TestStatus uint           `gorm:"column:test_status;type:bigint;comment:考试状态: 1:进行中 2:已结束 3:未开始;not null;" json:"test_status"` // 考试状态: 1:进行中 2:已结束 3:未开始
	TestTime   uint           `gorm:"column:test_time;type:bigint;not null;" json:"test_time"`
	CreatedAt  time.Time      `gorm:"column:created_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" json:"created_at"`
	UpdatedAt  time.Time      `gorm:"column:updated_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" json:"updated_at"`
	DeletedAt  gorm.DeletedAt `gorm:"column:deleted_at;type:datetime(3);default:NULL;" json:"deleted_at"`
}

func (u *User) TableName() string {
	return "user"
}

func (u *User) GetUserBy(mobile string) error {
	return global.DB.Where("mobile=?", mobile).Limit(1).First(&u).Error
}

func (u *User) Create() error {
	return global.DB.Create(&u).Error
}
